home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000006_icon-group-sender _Wed Jul 2 09:27:28 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  1KB

  1. Received: from kingfisher.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Wed, 2 Jul 1997 12:29:46 MST
  2. Received: by kingfisher.CS.Arizona.EDU; (5.65v3.2/1.1.8.2/08Nov94-0446PM)
  3.     id AA20607; Wed, 2 Jul 1997 12:29:46 -0700
  4. Message-Id: <199707021627.JAA09747@orpheus.gemini.edu>
  5. From: swampler@noao.edu (Steve Wampler)
  6. Date: Wed, 2 Jul 1997 09:27:28 MST
  7. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  8. To: icon-group@cs.arizona.edu
  9. Subject: A small puzzle
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11. Status: RO
  12.  
  13. Recently, the SNOBOL4 mailing list has been playing with ways (in
  14.   SNOBOL4/SPITBOL) of writing a procedure to return the longest
  15.   common prefix between strings.  This is kinda a fun thing to
  16.   play with in Icon also, so I thought I'd invite people to post
  17.   their solutions to this problem.
  18.  
  19.   Write a procedure lcp(s1,s2) that returns the longest common
  20.   prefix of strings s1 and s2.  For example,
  21.  
  22.     write(lcp("fool","foodchain"))
  23.  
  24.   would output "foo", while
  25.  
  26.     write(lcp("aardvark","elephant"))
  27.  
  28.   would output "" (i.e. th
  29.  null string).
  30.  
  31.   I have two basic solutions I like, one using string scanning (my
  32.   favorite) and one without string scanning.  I also have a couple
  33.   derivatives that attempt to improve performance through heuristics.
  34.  
  35.  
  36. -- 
  37. Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under AURA)]
  38. O Sibile, si ergo, fortibus es inero.
  39. Nobile, demis trux.  Demis phulla causan dux.
  40.